package Frame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import Function.FCMapLibrary;
import VWorldGameStudio.FCMap;

public class FCOpenMap extends JDialog {
	public FCOpenMap(FCMapLibrary mapl, MapEditJpanel jpa, JTextField mapname, JLabel mapsize, JTextArea mapinfo) {
		setModal(true);
		setTitle("保存地图");
		setBounds(0, 0, 205, 130);
		setLayout(null);
		setLocationRelativeTo(null);
		setResizable(false);

		JLabel qw = new JLabel("地图名称", JLabel.CENTER);
		qw.setBounds(10, 10, 180, 20);
		this.add(qw);

		JComboBox<String> as = new JComboBox<String>();
		as.setBounds(10, 40, 180, 20);
		for (int i = 0; i < mapl.getMapNum(); i++)
			as.addItem(mapl.getMapNameOfID(i));
		this.add(as);

		JButton zx = new JButton("确认");
		zx.setBounds(10, 70, 180, 20);
		this.add(zx);

		zx.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (mapl.getMapNum() > 0) {
					if (jpa.isSave()) {
						FCMap mm = mapl.getMapOfName(as.getSelectedItem().toString());
						jpa.setNewMap(mm);
						mapname.setText(mm.getName());
						mapsize.setText(mm.getMapWidth() + "*" + mm.getMapHeight());
						mapinfo.setText(mm.getInfo());
						dispose();
					} else
						new FCTip("打开地图", "当前地图并未保存!");
				} else
					new FCTip("打开地图", "没有可以打开的地图!");
			}
		});
		setVisible(true);
	}
}
